#ifndef VULKAN_TEXTURE_H
#define VULKAN_TEXTURE_H

#include <vulkan/vulkan.h>
#include "stb/stb_image.h"

#ifdef __cplusplus
extern "C" {
#endif

// 主要函数
VkResult createTexture(VkDevice device, VkPhysicalDevice physicalDevice,
                      VkCommandPool commandPool, VkQueue queue,
                      const char* imagePath, VkImage* textureImage,
                      VkDeviceMemory* textureImageMemory);

stbi_uc* loadImageFromRawFile(const char* imagePath, int* width, int* height, int* channels);

// 辅助函数
VkResult createBuffer(VkDevice device, VkPhysicalDevice physicalDevice, VkDeviceSize size,
                     VkBufferUsageFlags usage, VkMemoryPropertyFlags properties,
                     VkBuffer* buffer, VkDeviceMemory* bufferMemory);

uint32_t findMemoryType(VkPhysicalDevice physicalDevice, uint32_t typeFilter, 
                       VkMemoryPropertyFlags properties);

VkResult transitionImageLayout(VkDevice device, VkCommandPool commandPool, VkQueue queue,
                              VkImage image, VkFormat format, VkImageLayout oldLayout,
                              VkImageLayout newLayout);

VkResult copyBufferToImage(VkDevice device, VkCommandPool commandPool, VkQueue queue,
                          VkBuffer buffer, VkImage image, uint32_t width, uint32_t height);

// 命令缓冲区辅助函数
VkCommandBuffer beginSingleTimeCommands(VkDevice device, VkCommandPool commandPool);
void endSingleTimeCommands(VkDevice device, VkCommandPool commandPool, 
                          VkQueue queue, VkCommandBuffer commandBuffer);

#ifdef __cplusplus
}
#endif

#endif // VULKAN_TEXTURE_H